<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.stylethem {
	color: #000 !important;
	font-weight: bold !important;
	font-size: 24px !important;
}
.stylethem1 {font-weight: bold !important;}
-->
</style>
<script language="JavaScript" type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script language="JavaScript" type="text/javascript" src="ckeditor/sample.js"></script>
</head>
<body>
    <form action="?thamso=themdoitac" method="post" enctype="multipart/form-data" name="form1">
      <table width="400" border="0" align="center" cellpadding="3" cellspacing="3">
        <tr align="center" bgcolor="#333333">
          <td colspan="2"><span class="stylethem">Đối tác công ty</span></td>
        </tr>
        <tr bgcolor="#F2F2F2">
            <td width="20%">
                <strong>Link: </strong>
            </td>
            <td width="80%">
                <input type='text' name='txttsp' size='70'/>
            </td>
        </tr>
       <tr bgcolor="#F2F2F2">
        	<td width='20%'><strong>Hình ảnh: </strong></td>
        	<td width='80%'> 
            	<input type='file' name='hinh' style="width:100px" />
          	</td>
        </tr>
        <tr align="center" bgcolor="#CFCFCF">
        	<td width='20%'>&nbsp;</td>
			<td width='80%'><input type="submit" class="nut_chapnhan" value="Chấp nhận" name="them"></td>
        </tr>  
      </table>
    </form>
</body>
</html>
<?php
function ktfile($tenfile)
	{
		$pattern='#.+\.(gif|jpg|png)$#i';
		if(preg_match($pattern,$tenfile)==1)
		{
    		return 1;
		}
		else
		{
    		return 0;
		}
	}
	function upload_anh(){
		$hinh=$_FILES["hinh"]["name"];
		$duongdan_upload_anh="../images/doitac/$hinh";
		chong_90($hinh);
		move_uploaded_file($_FILES["hinh"]["tmp_name"],$duongdan_upload_anh);
	}
	if(isset($_POST["them"]))
	{
		if($_FILES["hinh"]["size"]>2000000)
		{
			echo"<script>alert('File Vượt quá dung lượng cho phép');</script>";
			return;
		}
		else
		{
			if($_FILES["hinh"]["error"]>0)
			{	
				echo"<script>alert('Lỗi Upload File')</script>";
				return;
			}
			else
			{
				if(ktfile($_FILES["hinh"]["name"])==1)
				{	
					
					$hinh=$_FILES["hinh"]["name"];
				}
				else
				{
					echo"<script>alert('Đuôi file không đúng')</script>";
				}
			}
		}
		chong_90($hinh);
		$link = $_POST['txttsp'];
		$sql = "INSERT INTO `doitac` (`madoitac`, `link`, `hinhanh`)
				VALUES (NULL , '$link', '$hinh')";
		$result = mysql_query($sql);
		if($result)
		{
			echo "<script>alert('Thêm thành công');</script>";
			echo "<script>window.location=('?thamso=dsdoitac');</script>";
		}
		else echo "<script>alert('Thêm không thành công');</script>";
		upload_anh();
	}
?>